package com.lanchetech.admin.controller;


import com.lanchetech.admin.aop.OperatorLog;
import com.lanchetech.bean.request.ShareActivityReq;
import com.lanchetech.bean.request.ShareDetailedReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.ShareActivitySpuVo;
import com.lanchetech.bean.vo.ShareActivityVo;
import com.lanchetech.bean.vo.ShareDetailedVo;
import com.lanchetech.bean.vo.SpuItemVO;
import com.lanchetech.common.exception.ResultCodeException;
import com.lanchetech.entity.ShareActivity;
import com.lanchetech.entity.ShareActivitySpu;
import com.lanchetech.service.ShareActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Api(value = "pc分享赚管理接口", tags = "分享赚管理接口")
@RequestMapping("/api/admin/sher")
@RestController
public class AdminShareActivityController {


    @Autowired
    private ShareActivityService shareActivityService;

    @PostMapping("/getShareActivity")
    @ApiOperation("获取分享赚列表")
    public ResultData<BasePageResp<ShareActivityVo>> getShareActivity(@RequestBody ShareActivityReq shareActivityReq) {
        return shareActivityService.getShareActivity(shareActivityReq);
    }

    @PostMapping("/freeze/{id}")
    @OperatorLog("冻结分享赚")
    @ApiOperation("冻结分享赚")
    public BaseResp freeze(@PathVariable Long id) {
        BaseResp baseResp = new BaseResp();
        try {
            shareActivityService.freeze(id);
        } catch (ResultCodeException e) {
            baseResp.setResultCode(e.getResultCode());
        }
        return baseResp;
    }

    @GetMapping("/getBindSpu")
    @ApiOperation("获取绑定商品列表")
    public ResultData<List<SpuItemVO>> getBindSpu(@RequestParam Long shareActivityId) {
        ResultData<List<SpuItemVO>> vo = shareActivityService.getBindSpu(shareActivityId);
        return vo;
    }

    @PostMapping("/getShareDetailed")
    @OperatorLog(value = "佣金/嗨币列表")
    @ApiOperation(value = "佣金/嗨币列表")
    public ResultData<BasePageResp<ShareDetailedVo>> getShareDetailed(@RequestBody ShareDetailedReq req) {
        return shareActivityService.getShareDetailed(req);
    }

    @PostMapping("/freezeOrNot/{id}")
    @OperatorLog(value = "佣金/嗨币是否冻结")
    @ApiOperation(value = "佣金/嗨币是否冻结")
    public BaseResp freezeOrNot(@PathVariable Long id) {
        BaseResp baseResp = new BaseResp();
        try {
            shareActivityService.freezeOrNot(id);
        } catch (ResultCodeException e) {
            baseResp.setResultCode(e.getResultCode());
        }
        return baseResp;
    }
}
